//
//  XJStatusViewModel.m
//  weiboOC
//
//  Created by 徐绩 on 16/4/22.
//  Copyright © 2016年 ayumi. All rights reserved.
//

#import "XJStatusViewModel.h"

@implementation XJStatusViewModel

-(void)setStatusModel:(XJStatusModel *)statusModel{

    _statusModel = statusModel;
    [self dealMemberImage];
    [self dealSource];
    
    if (statusModel.retweeted_status) {
        
        self.retweetText = [NSString stringWithFormat:@"@%@:%@",statusModel.retweeted_status.user.name,statusModel.retweeted_status.text];
        
    }
}

-(void)dealMemberImage{

    int brank = self.statusModel.user.mbrank;
    if (brank >0 && brank <7) {
        
        _memberImage = [UIImage imageNamed:[NSString stringWithFormat:@"common_icon_membership_level%d",brank]];
    }
}

-(void)dealSource{

    NSString *source = self.statusModel.source;
    if (source) {        
//        <a href=\"http://app.weibo.com/t/feed/5B6hUc\" rel=\"nofollow\">iPhone 6s Plus</a>
        
        NSUInteger startIndex =  [source rangeOfString:@"\">"].location;
        NSInteger endIndex = [source rangeOfString:@"</"].location;
        NSInteger length = endIndex - startIndex;        
        
        if (startIndex != NSNotFound) {
            
            NSString *range = [source substringWithRange:NSMakeRange(startIndex + 2, length)];
            source = range;
            self.sourceText = [NSString stringWithFormat:@"来自%@",source];            
        }
    }
    
}


@end
